// ignore_for_file: must_be_immutable, prefer_typing_uninitialized_variables

import 'package:aitao_flutter/common_ui/empty_view.dart';
import 'package:aitao_flutter/style/color_style.dart';
import 'package:aitao_flutter/style/edgeInsets_style.dart';
import 'package:aitao_flutter/utils/alert_utils.dart';
import 'package:flutter/material.dart';
import '../../model/hello_text_model.dart';

class SayHelloTextPage extends StatelessWidget {
  SayHelloTextPage(
      {Key? key, required this.textList, required this.deleteCallBack})
      : super(key: key);
  List<HelloTextModel> textList;
  var deleteCallBack;

  @override
  Widget build(BuildContext context) {
    return textList.isEmpty
        ? EmptyView()
        : Container(
            padding: EdgeInsetsStyle.only(left: 20, right: 20),
            child: ListView.builder(
              itemBuilder: (context, index) {
                return GestureDetector(
                  child: Padding(
                      padding: EdgeInsetsStyle.only(top: 10, bottom: 10),
                      child: setHelloTextStyle(textList[index])),
                  onLongPress: () {
                    AlertUtils().showCenterTipsDialog(context, (e) {
                      deleteHelloText(index);
                    }, '删除', '是否删除该条招呼?');
                  },
                );
              },
              itemCount: textList.length,
            ));
  }

  Text setHelloTextStyle(HelloTextModel model) {
    if (model.isAudit == 0) {
      return Text(
        '${model.msg}(审核中)',
        textAlign: TextAlign.center,
        style: const TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 14,
            color: ColorStyle.aaaaaaColor),
      );
    } else if (model.isAudit == 2) {
      return Text(
        '${model.msg}(审核不通过)',
        textAlign: TextAlign.center,
        style: const TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 14,
            color: ColorStyle.aaaaaaColor),
      );
    } else {
      return Text(
        '${model.msg}',
        textAlign: TextAlign.center,
        style: const TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 14,
            color: ColorStyle.zeroColor),
      );
    }
  }

  void deleteHelloText(int index) async {
    deleteCallBack(textList[index]);
  }
}
